package com.kirayous.gulimall.product.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * @author KiraYous
 * @version V1.0
 * @Package com.kirayous.gulimall.product.config
 * @date 2022/3/31 20:04
 */
@Configuration
public class MySessionConfig {

    //TODO 待研究
    @Bean
    public CookieSerializer cookieSerializer(){
        DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();

        cookieSerializer.setDomainName("1.14.151.242");
        cookieSerializer.setCookieName("GULISESSION");

        return cookieSerializer;
    }


    //用于配置spring redis 的序列化，使用value使用json进行格式化，
    //使用jason进行保存value可以做到让不同语言共享这个value
    //假如只使用java的序列化机制，那么反序列化只能由java语言进行反序列化，而php不行
    @Bean
    public RedisSerializer<Object> springSessionDefaultRedisSerializer() {
        return new GenericJackson2JsonRedisSerializer();
    }
}
